package com.fadadianqi.logistics.admin.net;

import java.io.Serializable;
import java.nio.ByteBuffer;

/**
 * 4+8+4+4+4+4+4
 * <br/>
 * length+id+majorVersion+minorVersion+microVersion+type+action
 *
 * @author aroot
 */
public class PacketHead implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = -7530406151648642173L;

    public static final int LEN = 8;

    public static void main(String[] args) {
        PacketHead p = new PacketHead(Action.SMS_PACKET);
        System.out.println(p.toBytes().length);
    }

    private int action;
    private int bodyLen = 0;

    public PacketHead(int action) {
        this.action = action;
    }

    public void setBodyLen(int bodyLen) {
        this.bodyLen = bodyLen;
    }

    public byte[] toBytes() {
        ByteBuffer buffer = ByteBuffer.allocate(LEN);
        buffer.putInt(action);
        buffer.putInt(bodyLen);
        return buffer.array();
    }

    public int getAction() {
        return action;
    }
}
